package com.mixcus.server.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.mixcus.server.dao.StudentDao;
import com.mixcus.server.dto.StudentCourseDto;
import com.mixcus.server.dto.StudentPaginationDto;
import com.mixcus.server.entity.PageResult;
import com.mixcus.server.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentDao studentDao;

    @Override
    public PageResult findPage(StudentPaginationDto spd) {

        Map<String, Object> map = new HashMap<>();

        map.put("studentId",spd.getStudentId());
        map.put("ascendOrNot",spd.getAscendingOrNot());
        map.put("sortBy",spd.getSortBy());
        map.put("courseName",spd.getCourseName());
        PageHelper.startPage(spd.getCurrentPage(),spd.getPageSize());

        Page<StudentCourseDto> page = studentDao.findPage(map);

        return new PageResult(page.getTotal(),page.getResult());
    }
}

